<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../react18/react.development.js"></script>
    <script src="../react18/react-dom.development.js"></script>
    <script src="../react18/babel.min.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Message extends React.Component{
            state={
                opacity:1,
                timer:null
            }
            componentDidMount(){
                let {opacity}=this.state;
                let timer = setInterval(()=>{
                    opacity-=0.01;
                    if(opacity<=0){
                        opacity=1
                    }
                    console.log(opacity);
                    this.setState({
                        opacity
                    })
                },100);
                this.setState({timer:timer})
            }
            componentWillUnmount(){
                const {timer} = this.state;
                clearInterval(timer)
            }
            render(){
                return <div>
                    <h2  style={{ opacity: this.state.opacity }}>可偏偏，风渐渐</h2>
                    </div>
            }
        }

        class App extends React.Component{
            state={
                isStudyReact:true
            };
            render(){
                const {isStudyReact}=this.state;
                return <div>
                    {isStudyReact?<Message />:""}
                    <button onClick={this.changeStudyState}>
                        {isStudyReact?"把距离吹得好远":"好不容易"}</button>
                    </div>
            }
            changeStudyState=()=>{
                const {isStudyReact}=this.state;
                this.setState({
                    isStudyReact:!isStudyReact
                })
            }
        }
        ReactDOM.createRoot(document.getElementById("app")).render(<App />)
    </script>
</body>
</html>